﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections.Specialized;

namespace Silmoon.DNS.Monitoring
{
    public class Configure
    {
        GBC g;
        public string db_mongodb_server;
        public string db_mongodb_monitor_database;
        public string db_mongodb_username;
        public string db_mongodb_password;
        public string db_mongodb_type;

        public string db_mysql_server;
        public string db_mysql_database;
        public string db_mysql_username;
        public string db_mysql_password;

        public string webapi;
        public int monitor_timespan;

        public Configure(GBC _g)
        {
            g = _g;
            loadConfigureFile();
        }
        void loadConfigureFile()
        {
            string configFilePath = System.Windows.Forms.Application.StartupPath + "/configure.conf";

            if (!string.IsNullOrEmpty(g.Parameters["--configure"]))
                configFilePath = g.Parameters["--configure"];
            string[] configureLine = File.ReadAllLines(configFilePath);
            NameValueCollection parameters = SmString.AnalyzeNameValue(configureLine, "=");

            db_mongodb_server = parameters["db_mongodb_server"];
            db_mongodb_monitor_database = parameters["db_mongodb_monitor_database"];
            db_mongodb_username = parameters["db_mongodb_username"];
            db_mongodb_password = parameters["db_mongodb_password"];
            db_mongodb_type = parameters["db_mongodb_type"];

            db_mysql_server = parameters["db_mysql_server"];
            db_mysql_database = parameters["db_mysql_database"];
            db_mysql_username = parameters["db_mysql_username"];
            db_mysql_password = parameters["db_mysql_password"];

            webapi = parameters["webapi"];
            monitor_timespan = int.Parse(parameters["monitor_timespan"]);
        }
    }
}
